import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import { resolve } from 'path';
function pathResolve(dir: string) {
  return resolve(__dirname, '.', dir);
}
const port = 8000
const globalUrl = "http://localhost:9000"
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  base: './',
  root: process.cwd(),
  resolve: {
    alias: [
      {
        // /@/xxxx  =>  src/xxx
        find: /^\/@\//,
        replacement: pathResolve('src') + '/',
      },
    ],
  },
  server: {
    port: port,
    proxy: {
      '/api': {
        target: `ws://${globalUrl}`, // 修改后台接口地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    },
    hmr: {
      overlay: true,
    },
  },

  build: {
    outDir: 'dist',
    polyfillDynamicImport: false,
    terserOptions: {
      compress: {
        keep_infinity: true,
        // Used to delete console in production environment
        drop_console: true,
      },
    },
    // Turning off brotliSize display can slightly reduce packaging time
    brotliSize: false,
    chunkSizeWarningLimit: 1200,
  },
})
